from django.db import models
from apps.common.base.models import BaseModel
from apps.system.lessee.models import Lessee
from apps.merchant.cate.models import Cate
from apps.merchant.activity.models import Activity

class Item(BaseModel):
    '''商品模型'''
    status = (
        (0, "关闭"),
        (1, "正常"),
    )
    checkStatus = (
        ('PASS', "审核通过"),
        ('CHECKING', "审核中"),
        ('REFUSE', "审核拒绝"),
    )
    lessee = models.ForeignKey(Lessee, related_name="lessee_item", verbose_name='租户',
                               on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False)
    cate = models.ForeignKey(Cate, related_name='cate_item', verbose_name='分类', on_delete=models.SET_NULL, null=True,
                             blank=True, db_constraint=False)
    activity = models.ForeignKey(Activity, related_name='activity_item', verbose_name='活动', on_delete=models.SET_NULL, null=True,
                             blank=True, db_constraint=False)
    name = models.CharField("商品名称", max_length=200, blank=True, default='')
    shelfNum = models.CharField("货架号", max_length=200, blank=True, default='')
    coverPhotos = models.CharField("商品轮播图", max_length=500, blank=True, default='')
    detailPhotosRichText = models.CharField("商品详情富文本", max_length=10000, blank=True, default='')
    sales = models.IntegerField("销量", default=0)
    stock = models.IntegerField("总库存", default=0)
    publicity = models.CharField("宣传语", max_length=200, blank=True, default='')
    intro = models.CharField("商品介绍", max_length=2000, blank=True, default='')
    status = models.IntegerField("上架/下架", choices=status, default=0)
    checkStatus = models.CharField("审核状态", max_length=200, choices=checkStatus, blank=True, default='PASS')
    keyword = models.CharField("关键字", max_length=200, blank=True, default='')
    isTransportFee = models.BooleanField("是否需要运费", blank=True, default=False)
    isOnlinePay = models.BooleanField("是否线上支付", blank=True, default=False)
    transportFee = models.DecimalField("运费", max_digits=10, decimal_places=2, default=0)
    minShopCount = models.IntegerField("最小购买数量", default=1)
    maxShopCount = models.IntegerField("最大购买数量", default=0)
    isSingleSpec = models.IntegerField("是否单规格", blank=True, default=1)
    isCheckStock = models.IntegerField("是否校验库存", blank=True, default=0)


class Meta:
        verbose_name = 'Item'
        verbose_name_plural = verbose_name
